package com.chixing.day10_hashcode_exception;

import java.util.Objects;

public class Student {
    private String stuName;
    private int stuAge;
    private long stuPhoneNumber;


    public Student(String stuName, int stuAge, long stuPhoneNumber) {
        this.stuName = stuName;
        this.stuAge = stuAge;
        this.stuPhoneNumber = stuPhoneNumber;
    }

    public Student() {

    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }

    public long getStuPhoneNumber() {
        return stuPhoneNumber;
    }

    public void setStuPhoneNumber(long stuPhoneNumber) {
        this.stuPhoneNumber = stuPhoneNumber;
    }
    //重写equals方法，比较所有的属性


 /*   @Override
    public boolean equals(Object obj) {
       if(obj == null || this.getClass() != obj.getClass())
           return false;
       if (obj == this)
           return true;

       Student anotherStu = (Student) obj;

        return super.equals(obj);
    }*/

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return stuAge == student.stuAge && stuPhoneNumber == student.stuPhoneNumber && Objects.equals(stuName, student.stuName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(stuName, stuAge, stuPhoneNumber);
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuName='" + stuName + '\'' +
                ", stuAge=" + stuAge +
                ", stuPhoneNumber=" + stuPhoneNumber +
                '}';
    }
}
